﻿using Cinch;
using FR.SAFTAnalyser.Model;
using FR.SAFTAnalyser.Model.Stocks;
using FR.SAFTAnalyser.Services;
using FR.SAFTAnalyser.ViewModels.Pane;
using MEFedMVVM.Common;
using System;
using System.ComponentModel;
using System.ComponentModel.Composition;

namespace FR.SAFTAnalyser.ViewModels
{
    public class StockHeaderViewModel : DocumentPartViewModel
    {
        public StockHeaderViewModel()
            : base("Cabeçalho Stock")
        {
            if (!Designer.IsInDesignMode)
            {
                Mediator.Instance.Register(this);
            }
        }

        internal override void ResetSaftFile()
        {
            this.Cabecalho = null;
        }

        [MediatorMessageSink(MessageType.STOCK_FILE_OPENED)]
        private void LoadHeader(StockFile stock)
        {
            this.Cabecalho = stock.StockHeader;
        }

        StockHeader cabecalho;
        public StockHeader Cabecalho
        {
            get
            {
                if (cabecalho == null && SAFT.StockAnalyser.Instance.StockFile != null)
                    cabecalho = SAFT.StockAnalyser.Instance.StockFile.StockHeader;
                return cabecalho;
            }
            set
            {
                cabecalho = value;
                NotifyPropertyChanged(ObservableHelper.CreateArgs<StockHeaderViewModel>(x => x.Cabecalho));
            }
        }
    }
}
